package com.fh.shop.api.mq.config;

import com.fh.shop.api.common.SystemConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {

    // directExchange==================================================

    @Bean
    public Queue redQueue() {
        return new Queue(MQConstant.TestDirect.QUEUE);
    }

    @Bean
    public Queue blueQueue() {
        return new Queue(MQConstant.TestDirect.BLUE_QUEUE);
    }

    @Bean
    public Queue queue1() {
        return new Queue(MQConstant.TestDirect.QUEUE1);
    }

    @Bean
    public DirectExchange testDirectExchange() {
        return new DirectExchange(MQConstant.TestDirect.EX);
    }

    @Bean
    public Binding redBinding() {
        return BindingBuilder.bind(redQueue()).to(testDirectExchange()).with(MQConstant.TestDirect.ROUTE_KEY);
    }

    @Bean
    public Binding blueBinding() {
        return BindingBuilder.bind(blueQueue()).to(testDirectExchange()).with(MQConstant.TestDirect.BLUE_ROUTE_KEY);
    }

    @Bean
    public Binding queue1Binding() {
        return BindingBuilder.bind(queue1()).to(testDirectExchange()).with(MQConstant.TestDirect.ROUTE_KEY);
    }

    // fanout类型交换机==============================================
    @Bean
    public Queue q1() {
        return new Queue(MQConstant.TestFanout.QUEUE1);
    }
    @Bean
    public Queue q2() {
        return new Queue(MQConstant.TestFanout.QUEUE2);
    }
    @Bean
    public FanoutExchange testFanout() {
        return new FanoutExchange(MQConstant.TestFanout.EX);
    }
    @Bean
    public Binding q1Binding() {
        return BindingBuilder.bind(q1()).to(testFanout());
    }
    @Bean
    public Binding q2Binding() {
        return BindingBuilder.bind(q2()).to(testFanout());
    }
    // Topic类型的交换机
    @Bean
    public Queue q5() {
        return new Queue(MQConstant.TestTopic.Q5);
    }
    @Bean
    public Queue q4() {
        return new Queue(MQConstant.TestTopic.Q4);
    }
    @Bean
    public TopicExchange testTopic() {
        return new TopicExchange(MQConstant.TestTopic.EX);
    }
    @Bean
    public Binding q4Binding() {
        return BindingBuilder.bind(q4()).to(testTopic()).with(MQConstant.TestTopic.KEY1);
    }
    @Bean
    public Binding q5Binding() {
        return BindingBuilder.bind(q5()).to(testTopic()).with(MQConstant.TestTopic.KEY2);
    }

    // mail相关的配置
    @Bean
    public Queue mailQueue() {
        return new Queue(MQConstant.Mail.QUEUE);
    }
    @Bean
    public DirectExchange mailDirectEx() {
        return new DirectExchange(MQConstant.Mail.EX);
    }
    @Bean
    public Binding mailBinding() {
        return BindingBuilder.bind(mailQueue()).to(mailDirectEx()).with(MQConstant.Mail.ROUTE_KEY);
    }
    // pay相关的配置
    @Bean
    public Queue scoreQueue() {
        return new Queue(MQConstant.Pay.SCORE_QUEUE);
    }
    @Bean
    public Queue saleQueue() {
        return new Queue(MQConstant.Pay.SALE_QUEUE);
    }
    @Bean
    public FanoutExchange payEx() {
        return new FanoutExchange(MQConstant.Pay.EX);
    }
    @Bean
    public Binding scoreBinding() {
        return BindingBuilder.bind(scoreQueue()).to(payEx());
    }
    @Bean
    public Binding saleBinding() {
        return BindingBuilder.bind(saleQueue()).to(payEx());
    }
}
